# import cv2
# img=cv2.imread("puppy.jpg")
# if img is not None and len(img.shape)==3:
#     print('img.shape:',img.shape)
#     show_img('img',img,-1)
#     if img.shape[2]==3:
#         b,g,r=cv2.split(img)
#         show_img('b',b,-1)
#         show_img('g', g, -1)
#         show_img('r', r, -1)
#         show_img('a', a, -1)



import cv2

img = cv2.imread("1.PNG")

if img is not None and len(img.shape) == 3:
    print('img.shape:', img.shape)
    cv2.imshow('img', img)
    cv2.waitKey(0)

    # 检查图像是否有 3 个通道
    if img.shape[2] == 3:
        # 分离 BGR 通道
        b, g, r = cv2.split(img)

        # 显示每个通道
        cv2.imshow('b', b)
        cv2.waitKey(0)
        cv2.imshow('g', g)
        cv2.waitKey(0)
        cv2.imshow('r', r)
        cv2.waitKey(0)

# 关闭所有 OpenCV 窗口
cv2.destroyAllWindows()